package cn.kgc.housedemo01.service;

import cn.kgc.housedemo01.mapper.HouseInfoMapper;
import cn.kgc.housedemo01.mapper.HouseTypeMapper;
import cn.kgc.housedemo01.mapper.viewsInfoTypeMapper;
import cn.kgc.housedemo01.pojo.HouseInfo;
import cn.kgc.housedemo01.pojo.HouseType;
import cn.kgc.housedemo01.pojo.viewsInfoType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class HouseServiceImpl implements  HouseService {
    @Resource
    HouseInfoMapper houseInfoMapper;
    @Resource
    viewsInfoTypeMapper  viewsInfoTypeMapper;
    @Resource
    HouseTypeMapper houseTypeMapper;
    @Override
    public PageInfo<viewsInfoType> selectAll(Integer pageNum) {
        PageHelper.startPage(pageNum,3);
        List<viewsInfoType> infoTypeList = viewsInfoTypeMapper.selectByExample(null);
        PageInfo<viewsInfoType> pageInfo=new PageInfo<>(infoTypeList);
        return pageInfo;
    }

    @Override
    public List<HouseType> selectAllHouseType() {
        return houseTypeMapper.selectByExample(null);
    }

    @Override
    public Integer saveHouse(HouseInfo houseInfo) {
        return houseInfoMapper.insert(houseInfo);
    }

    @Override
    public HouseInfo selectAllById(Integer houseid) {
        return houseInfoMapper.selectByPrimaryKey(houseid);
    }

    @Override
    public Integer updateHouse(HouseInfo houseInfo) {
        return houseInfoMapper.updateByPrimaryKeySelective(houseInfo);
    }
}
